package com.base.cn.platform.os.controller.agent.config;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.service.course.agent.config.AgentConfigService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 后台分销配置Controller
 *
 * @author LIZHIPENG
 * @since 2018/5/4
 */
@Controller
@RequestMapping("/admin/agent/config")
public class AdminAgentConfigController extends AdminBaseController {

    private Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();

    @Autowired
    private AgentConfigService agentConfigService;

    /**
     * 获取分销系统配置
     * @param model
     * @return
     */
    @RequestMapping("/queryAgentConfigList")
    public String queryAgentConfigList(Model model){
        Map<String,Object> agentConfigMap = agentConfigService.queryAgentConfigList();
        model.addAttribute("agentConfigMap", agentConfigMap);
        return resultPage("/agent/config/agent-config");
    }

    /**
     * 保存分销配置
     * @param params
     * @return
     */
    @RequestMapping("/saveAgentConfig")
    @ResponseBody
    public Map<String, Object> saveAgentConfig(@RequestBody Map<String, String> params){
        String _params = gson.toJson(params);
        return agentConfigService.saveAgentConfig(_params);
    }
}
